package org.dromara.common.core.exception.base

import org.dromara.common.core.utils.MessageUtils

/**
 * 带数据的异常
 *
 * @author Blutter.J
 */
class DataBaseException(
    val module: String?,
    val data: Any?,
    val code: String?,
    val args: Array<Any>?,
    private val defaultMessage: String?
) : RuntimeException() {
    override val message: String
        get() {
            return if (code?.isNotEmpty() == true) {
                MessageUtils.message(code, args)
            } else {
                defaultMessage
            } ?: "未知异常"
        }

    constructor(module: String, code: String, args: Array<Any>) : this(module, null, code, args, null)
    constructor(module: String, defaultMessage: String) : this(module, null, null, null, defaultMessage)
    constructor(code: String, args: Array<Any>) : this(null, null, code, args, null)
    constructor(defaultMessage: String) : this(null, null, null, null, defaultMessage)
    constructor(module: String, data: Any, code: String, args: Array<Any>) : this(module, data, code, args, null)
    constructor(module: String, data: Any, code: String): this(module, data, code, null, null)
}
